import { createPageTemplateConfig, PageTemplate } from '@/components';
import useIntlCustom from '@/hooks/useIntlCustom';
import { getPageConfig, type OfflineRecord } from './pageConfig';

const OfflinePage = () => {
  // 使用 useIntlCustom Hook
  const { translate } = useIntlCustom();

  // 在组件内部调用，传入 translate 函数
  const pageConfig = getPageConfig(translate);

  // 统一的操作处理函数
  const handleAction = (actionType: string, record: OfflineRecord) => {
    console.log('Action triggered:', actionType, record);
  };

  // 使用配置构建器创建页面配置
  const templateConfig = createPageTemplateConfig<OfflineRecord>()
    .setSearchConfig({
      fields: pageConfig.searchFields,
    })
    .setTableConfig({
      columns: pageConfig.columns,
      rowKey: 'paramIndex',
      props: {
        scroll: { x: 1200 },
        size: 'middle',
      },
    })
    .setFormConfig({
      fields: pageConfig.formFields,
    })
    .setActionConfig({
      permissions: {
        create: false,
        update: false,
        delete: false,
        view: false,
      },
      customActions: [
        {
          key: 'fieldManage',
          label: translate('common', 'fieldManage'),
          icon: null,
        },
      ],
      onAction: handleAction,
    })
    .setCrudConfig(pageConfig.crudConfig)
    .build();

  return <PageTemplate<OfflineRecord> {...templateConfig} />;
};

export default OfflinePage;
